#define _CRT_SECURE_NO_WARNINGS 1
#include<string>
class Solution {
public:
    int balancedStringSplit(std::string s) {
        int d = 0;
        int ans = 0;
        for (auto ch : s)
        {
            ch == 'L' ? d++ : d--;
            if (d == 0)
            {
                ans++;
            }
        }
        return ans;
    }
};